package com.Algorithm.HUAWEI.four20220505;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2022/05/12/14:05
 * @Description:
 * @Target:
 */
public class 查找两个字符串a_b中的最长公共子串 {
    /*
    *
    * 输入：
        abcdefghijklmnop
        abcsafjklmnopqrstuvw
        输出：
        jklmnop
    *
    *
    * */


    public static void main(String[] args) throws Exception{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        String ss1 = in.readLine();
        String ss2 = in.readLine();
        int maxIndex = 0;
        int tempMax = 0;

        if (ss2.length()>ss1.length()){
            String tempString  =  ss1;
            ss1 = ss2;
            ss2 = tempString;
        }
        for (int i = 0; i < ss2.length(); i++) {
            len = 0;
            index2Count = i;
            DP(ss1, ss2, 0, i);
            if (max>tempMax){
                maxIndex = i;
            }
            tempMax = Math.max(max,tempMax);
            max = 0;

        }

        for (int i = maxIndex; i < maxIndex+tempMax; i++) {
            System.out.print(ss2.charAt(i));
        }
//        System.out.println(tempMax+" "+ss2.charAt(maxIndex)+" "+maxIndex);
    }


    static int len;
    static int max;
    static int index2Count;
// 让ss2(index2),在ss1(index1)中找,如果一样,两个一起走,如果不一样,ss1走
    //
    static int DP(String ss1,String ss2,int index1,int index2){
        if (index1>ss1.length()-1 || index2>ss2.length()-1){
            return 0;
        }

        if (ss1.charAt(index1)!=ss2.charAt(index2)){
            index1++;
            index2 = index2Count;
            len = 0;
        }else {
            index1++;
            index2++;
            len++;
        }

        max = Math.max(len,max);
         DP(ss1,ss2,index1,index2);
        return len;

    }


}
